<template>
  <nm-container>
    <el-form label-width="80px" :inline="true" style="background:white;padding-top:20px">
      <el-form-item label="日期" prop="route_name">
        <el-date-picker v-model="form.busDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"> </el-date-picker>
      </el-form-item>
      <!-- <el-form-item label="截至日期" prop="route_name">
        <el-date-picker v-model="form.busDate" type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"> </el-date-picker>
      </el-form-item> -->
      <nm-button type="primary" @click="getData" text="查 询" style="margin-left:20px"></nm-button>
    </el-form>

    <el-table ref="topictable" :max-height="tabheight" :data="getList" border align="center" :header-cell-style="{ 'text-align': 'center', 'font-weight': 'bold', color: '#030202' }" :cell-style="{ 'text-align': 'center' }" style="width: 100%;text-align: center;">
      <!-- <el-table-column label="#" type="index" width="50"> </el-table-column> -->
      <el-table-column prop="check_date" label="日期" :formatter="dataFormat"> </el-table-column>
      <el-table-column prop="routeName" label="车号"> </el-table-column>
      <el-table-column prop="busTime" label="编号"> </el-table-column>
      <el-table-column prop="car_id" label="车牌号"> </el-table-column>
      <el-table-column prop="busType" label="公司代码"> </el-table-column>
      <el-table-column prop="company" label="车属公司"> </el-table-column>
      <el-table-column prop="total_seat" label="运营证"> </el-table-column>
      <el-table-column prop="lineCode" label="不合格项"> </el-table-column>
      <el-table-column prop="lineCode" label="列检员代码"> </el-table-column>
      <el-table-column prop="creator" label="列检员"> </el-table-column>
      <el-table-column prop="lineCode" label="列检员部门"> </el-table-column>
      <el-table-column prop="modifiedTime" label="列检时间"> </el-table-column>
    </el-table>
    <el-pagination background @current-change="paginationChange" layout="prev, pager, next" :total="total" />
  </nm-container>
</template>
<script>
import { mixins } from 'netmodular-ui'
import page from './page'
import cols from './cols'
// import SavePage from '../components/save'
// import detailList from '../components/detailList'

const api = $api.dispatch.vehicle_examine

export default {
  name: page.name,
  mixins: [mixins.list],
  // components: { SavePage, detailList },
  data() {
    return {
      total: 1,
      radio: '',
      form: {
        busDate: '',
      },
      getList: [],
      list: {
        title: page.title,
        cols,
        action: api.query,
        model: {
          /** 线路名称 */
          route_name: '',
        },
      },
      removeAction: api.remove,
      buttons: page.buttons,
      tabheight: 400,
    }
  },
  mounted() {
    this.form['Page.Index'] = 1
    this.form['Page.Size'] = 10
    this.$nextTick(() => {
      this.tabheight = window.innerHeight - this.$refs.topictable.$el.offsetTop - 150
    })
    this.getTime()
  },
  methods: {
    paginationChange(val) {
      this.form['Page.Index'] = val
      this.form['Page.Size'] = 10
      this.getData()
    },

    dataFormat(row, column) {
      let data = row[column.property]
      if (data === null) {
        return ''
      }
      let dt = new Date(data)
      return dt.getFullYear() + '-' + (dt.getMonth() + 1) + '-' + dt.getDate()
    },
    // 获取当天日期
    getTime() {
      let date = new Date()
      let y = date.getFullYear()
      let m = new Date().getMonth() + 1 < 10 ? '0' + (new Date().getMonth() + 1) : new Date().getMonth() + 1
      let d = date.getDate() < 10 ? '0' + new Date().getDate() : new Date().getDate()
      let isDate = y + '-' + m + '-' + d
      this.form.busDate = isDate
    },
    getData() {
      api.carcheckquery(this.form).then((res) => {
        if (res.rows.length == 0) {
          this.$message({
            message: '未查询到信息',
            type: 'warning',
          })
          this.getList = []
          this.total = 0
        } else {
          this.getList = res.rows
          this.total = res.total
        }
      })
    },
  },
}
</script>
